package shared;

public abstract class SortStarter<T extends Comparable<? super T>>  {
	
	/**
	 * Sorts the values in the provided buffer.
	 * The result of the sorting operation is provided in a new buffer.
	 * Does not change the provided buffer.
	 * @param buffer is a buffer with values that are sorted.
	 * @return a new buffer with the values of the input buffer. Sorted in ascending order.
	 */
	public Buffer<T> sort(final Buffer<T> buffer){
		final Buffer<T> clone = buffer.clone();
		final Buffer<SortInput<T>> input = new Buffer<SortInput<T>>();
		while(!clone.isEmpty()){
			input.put(new MyComparable<T>(clone.get()));
		}
		input.put(new MyStop<T>());
		return this.startSorter(input);
	}
	/**
	 * Starts the a sorter with the provided inputBuffer and provides the sorted result.
	 * @param inputBuffer is a buffer with {@link SortInput}s and a {@link MyStop} at the last position.
	 * @return the sorted inputBuffer without the {@link MyStop}.
	 */
	public abstract Buffer<T> startSorter(Buffer<SortInput<T>> inputBuffer);
}
